import logging
from config import BASE_HOST


class RegLoginApi:

    def __init__(self, session):
        self.session = session

    # 获取图片验证码接口
    def get_img_verify_code(self, r):
        url = (BASE_HOST + f'/common/public/verifycode1/{r}')
        resp = self.session.get(url)
        logging.info(f'获取图片验证码接口返回的状态码{resp.status_code}')
        return resp

    # 获取短信验证码接口
    def get_phone_verify_code(self, phone, imgVerifyCode_v, type_v):
        url = BASE_HOST + '/member/public/sendSms'
        data = {"phone": phone, "imgVerifyCode": imgVerifyCode_v, "type": type_v}
        resp = self.session.post(url, data=data)
        logging.info(f'获取短信验证接口返回的响应体数据{resp.json()}')
        return resp

    # 注册接口
    def user_register(self, phone, password, verifycode, phone_code, dy_server, invite_phone):
        url = BASE_HOST + '/member/public/reg'
        data = {"phone": phone,
                "password": password,
                "verifycode": verifycode,
                "phone_code": phone_code,
                "dy_server": dy_server,
                "invite_phone": invite_phone
                }
        resp = self.session.post(url, data=data)
        logging.info(f'获取注册接口返回的响应体数据{resp.json()}')
        return resp

    # 登录接口
    def user_login(self, keywords, password):
        url = BASE_HOST + '/member/public/login'
        data = {"keywords": keywords,
                "password": password
                }
        resp = self.session.post(url, data=data)
        logging.info(f'获取登录接口返回的响应体数据{resp.json()}')
        return resp
